<?php
// No direct access
defined('_JEXEC') or die;
$item = $this->item;

define('THUMB_WIDTH', 750);
?>

<?php 
require_once JPATH_ROOT . DS . 'jelibs/classes/util.class.php';

/*
$file 		= JPATH_ROOT . DS . 'images/je_products/upload/' . $item->images;
$thumbFile 	= JPATH_ROOT . DS . 'images/je_products/detail/' . $item->images;

JEUtil::resizeImage($file, $thumbFile, THUMB_WIDTH, null, false);
*/
$pathUpload = JPATH_ROOT . DS . 'images/je_products/upload/';
$pathThumb = JPATH_ROOT . DS . 'images/je_products/detail/';

$thumb = JEUtil::thumb($item->images, $pathUpload, $pathThumb, THUMB_WIDTH, null, false);
?>

<?php 
$class = '';
if($item->is_expired)
{
	echo '<h1 class="expired">[ Thông tin này đã hết hạn ]</h1>';
	$class = 'class="info-expired"';
}
?>
	

<div <?php echo $class; ?>>
	<h1><?php echo $item->name;?></h1>
	
	<div class="detail-image">
		<?php foreach ($thumb as $img): ?>
		<img alt="<?php echo $item->alias; ?>" src="images/je_products/detail/<?php echo $img; ?>">
		<?php endforeach; ?>
	</div>
		
	<div class="grid_13">
		
		<div class="description">
			<?php echo $item->description; ?>
		</div>
	</div>
	
	<div class="grid_6 last">
		<div class="box-header">Thông tin</div>
		
		<ul class="product-info">
			<li>
				<label>Phạm vi</label>
				<?php
				$loc = array(); 
				foreach ($item->locs as $location): ?>
					<?php $loc[] = ($location->name == 'all-location') ? 'Toàn Quốc' : $location->name; ?>
				<?php endforeach; 
				echo implode(', ', $loc);
				?>			
			</li>
			<?php 
			$publishUp 		= strtotime($item->publish_up);
			$today			= strtotime(date('Y-m-d'));
			$publishDown 	= strtotime($item->publish_down);
			
			$period = floor( ($publishDown - $today) / (24 * 60 * 60) );
			?>
			<li>
				<label>Ngày bắt đầu</label>
				<?php echo date('d/m/Y', $publishUp); ?>
			</li>
			<li>
				<label>Ngày kết thúc</label>
				<?php echo date('d/m/Y', $publishDown); ?>
			</li>
			<li>
				<label>Thời gian còn lại</label>
				<?php if($period >= 0): ?>
				<?php echo $period; ?> ngày
				<?php else: ?>
				Đã hết hạn
				<?php endif; ?>
			</li>
			<?php if($item->note): ?>
			<li>
				<label>Ghi chú</label>
				&nbsp;
				<div>
					<?php echo nl2br($item->note); ?>
				</div>
			</li>
			<?php endif; ?>
		</ul>
		
		<div class="clr"></div>
		
		<?php if(!empty($this->otherProducts)): ?>
		<div class="box-header">Thêm khuyến mại</div>
		
		<ul class="other-product">
			<?php foreach ($this->otherProducts as $i => $item): ?>
			<li>
				<?php 
				/*
				require_once JPATH_ROOT . DS . 'jelibs/classes/util.class.php';
				
				$file 		= JPATH_ROOT . DS . 'images/je_products/upload/' . $item->images;
				$thumbFile 	= JPATH_ROOT . DS . 'images/je_products/thumbs/thumb_' . $item->images;
				
				JEUtil::resizeImage($file, $thumbFile);
				*/
				
				$pathUpload = JPATH_ROOT . DS . 'images/je_products/upload/';
				$pathThumb = JPATH_ROOT . DS . 'images/je_products/thumbs/';
				
				$thumb = JEUtil::thumb($item->images, $pathUpload, $pathThumb, 220, 60);
				
				?>
				
				<?php $location = ($item->location_name == 'all-location') ? 'Toàn Quốc' : $item->location_name; ?>
				
				<a title="<?php echo $location . ': ' . $item->name; ?>" href="<?php echo JRoute::_('index.php?option=com_je_product&view=detail&id='. $item->id.':'.$item->alias); ?>">
					<img alt="<?php echo $item->alias; ?>" src="images/je_products/thumbs/<?php echo $thumb[0]; ?>">
					<strong><?php echo $location; ?></strong>: <?php echo $item->name;?>
				</a>
			</li>
			<?php endforeach; ?>
		</ul>
		
		<?php endif; ?>
	</div>
</div>

<div class="clr"></div>

<?php 
	$jeComments = JPATH_SITE . DS . 'components' . DS . 'com_je_comment' . DS . 'je_comment.php';

	if(file_exists($jeComments))
	{
		require_once $jeComments;
		Je_Comment::display($this->item->id, 'com_je_product', $this->item->name);
	}
?>